package br.inf.solutions.apresentacoes.ssp.model.bulletin.items;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import br.com.vexillum.model.annotations.SearchField;
import br.com.vexillum.model.annotations.Validate;
import br.com.vexillum.model.annotations.ValidatorClass;
import br.com.vexillum.util.DateCalc;
import br.com.vexillum.util.SpringFactory;
import br.inf.solutions.apresentacoes.ssp.control.RemovalController;
import br.inf.solutions.apresentacoes.ssp.model.Person;
import br.inf.solutions.apresentacoes.ssp.model.basics.SpeciesRemoval;
import br.inf.solutions.apresentacoes.ssp.model.bulletin.BulletinItem;
import br.inf.solutions.apresentacoes.ssp.model.bulletin.BulletinTopics;
import br.inf.solutions.apresentacoes.ssp.model.interfaces.IExistsPerson;

@SuppressWarnings("serial")
@ValidatorClass(validatorClass = "br.inf.solutions.apresentacoes.ssp.control.validator.RemovalValidator")
@Entity
@Table(name = "removal")
public class Removal extends BulletinItem implements IExistsPerson {

	public Removal() {
		super(new BulletinTopics(1l, "Removal", "/paginas/afastamento/retificacao.zul"));
	}
	
	public Removal(String text) {
		super(new BulletinTopics(1l, "Removal", "/paginas/afastamento/retificacao.zul"));
		setTextItem(text);
	}
	
	@Validate(notNull=true)
	@SearchField
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="species_removal_id",insertable=true, updatable=true, unique=false)
	private SpeciesRemoval species;
	
	@Validate(notNull=true)
	@SearchField(introspect=true)
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="person_id",insertable=true, updatable=true, unique=false)
	private Person person;
	
	@Validate(notNull=true)
	@SearchField
	@Column(name="date_initial", insertable=true, updatable=true, unique=false)
	private Date dateInitial;
	
	@Validate(notNull=true)
	@SearchField
	@Column(name="date_final", insertable=true, updatable=true, unique=false)
	private Date dateFinal;
	
	@Validate(min = 4, max = 4)
	@Column(name="exercise", nullable=true, insertable=true, updatable=true, unique=false)
	private Integer exercise;

	public SpeciesRemoval getSpecies() {
		return species;
	}

	public void setSpecies(SpeciesRemoval species) {
		this.species = species;
	}

	public Person getPerson() {
		return person;
	}

	public void setPerson(Person person) {
		this.person = person;
	}

	public Date getDateInitial() {
		return dateInitial;
	}

	public void setDateInitial(Date dateInitial) {
		this.dateInitial = dateInitial;
	}

	public Date getDateFinal() {
		return dateFinal;
	}

	public void setDateFinal(Date dateFinal) {
		this.dateFinal = dateFinal;
	}

	public Integer getExercise() {
		return exercise;
	}

	public void setExercise(Integer exercise) {
		this.exercise = exercise;
	}

	public Long getTimeDays() {
		return DateCalc.difDates(dateFinal, dateInitial);
	}

	@Override
	public  RemovalController getControl() {
		return SpringFactory.getController("removalController", RemovalController.class, null);
	}
	
}
